package com.example.administrator.shihuo.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.example.administrator.shihuo.Modle.ShaiWuModle;
import com.example.administrator.shihuo.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Sunshine on 2016/5/10.
 */
public class ShaiWuPullToReshAdapter extends BaseAdapter {
    private List<ShaiWuModle.DataBean.ListBean> mData;
    private LayoutInflater mInflater;
    private RecyclerAdapter recyclerAdapter;
    private Context mContext;
    private List<ShaiWuModle.DataBean.ListBean> tempData;

    public ShaiWuPullToReshAdapter(Context context, List<ShaiWuModle.DataBean.ListBean> datas) {
        this.mContext = context;
        this.mData = datas;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return (mData.size() / 2);
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = mInflater.inflate(R.layout.pull_item_layout, parent, false);
        RecyclerView recyclerView = (RecyclerView) convertView.findViewById(R.id.recycler_convertview_show);
        RecyclerView.LayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);

        if (mData.size() > 2 * position) {
            tempData = new ArrayList<>();
            tempData.add(mData.get(position * 2));
            tempData.add(mData.get(position * 2 + 1));
            recyclerAdapter = new RecyclerAdapter(mContext, tempData);
            recyclerView.setAdapter(recyclerAdapter);
        }
        return convertView;
    }
}
